# !/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2023/4/25 20:44
# @Author : xyjiang1216
# @Email : jiangxuyan@nudt.edu.cn
# @File : itp_sort.py
# @Version: OpenPlanner2.0
from typing import List

from OpenPlanner.examples.itp_demo.itp_algo_input import ITPStream
# from examples.itp_demo.itp_tabu import schedInfo


def itp_multi_stage_sort(sched1,
                         sched2,
                         stream_array: List[ITPStream]):
    f1 = sched1.flow_id
    f2 = sched2.flow_id

    s1 = stream_array[f1]
    s2 = stream_array[f2]

    if s1.pkt_num > s2.pkt_num:
        return 1
    elif s1.pkt_num < s2.pkt_num:
        return 0
    else:
        if len(s1.route) > len(s2.route):
            return 1
        elif len(s1.route) < len(s2.route):
            return 0
        else:
            if s1.latency_req_in_slot > s2.latency_req_in_slot:
                return 1
            elif s1.latency_req_in_slot < s2.latency_req_in_slot:
                return 0
            else:
                if s1.period_in_slot > s2.period_in_slot:
                    return 1
                else:
                    return 0
